import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../../controllers/counter.dart';

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  // 创建控制器实例
  // CounterController counterController = Get.put(CounterController());
  CounterController counterController = Get.find<CounterController>();
  @override
  Widget build(BuildContext context) {
    return Center(
      child: Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Obx(
            () => Text(
              "${counterController.counter}",
              style: Theme.of(context).textTheme.headlineLarge,
            ),
          ),
          SizedBox(height: 40),
          ElevatedButton(
            onPressed: () {
              counterController.inc();
            },
            child: Text("计数器+1"),
          ),
          SizedBox(height: 40),
          ElevatedButton(
            onPressed: () {
              Get.toNamed("/shop");
            },
            child: Text("跳转到shop"),
          ),
          SizedBox(height: 40),
          ElevatedButton(
            onPressed: () {
              Get.toNamed("/search");
            },
            child: Text("跳转到search"),
          ),
        ],
      ),
    );
  }
}
